package com.example.wangfanwangluo.wangfanboss;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class mine extends AppCompatActivity {
    private Typeface iconfont;
    private TextView exitv;
    private TextView usertv;
    private TextView loginpwtv;
    private TextView zhifupwtv;
    private TextView zhifustyletv;
    private RelativeLayout userly;
    private RelativeLayout loginpwly;
    private RelativeLayout zhifupwly;
    private LinearLayout root;
    private Dialog changepwdialog;
    private Window window;

//    protected void SetStatusBarColor() {
//        StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.mine_color));
//    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine);
        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null){
            actionbar.hide();
        }
//        ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
//        View statusBarView = new View(window.getContext());
//        int statusBarHeight = getStatusBarHeight(window.getContext());
//        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, statusBarHeight);
//        params.gravity = Gravity.TOP;
//        statusBarView.setLayoutParams(params);
//        statusBarView.setBackgroundColor(Color.parseColor("#081938"));
//        decorViewGroup.addView(statusBarView);
        initViews();


    }

    //获取系统状态栏的高度
    private static int getStatusBarHeight(Context context) {
        int statusBarHeight = 0;
        Resources res = context.getResources();
        int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = res.getDimensionPixelSize(resourceId);
        }
        return statusBarHeight;
    }
    //初始化ui
    public void initViews(){
        iconfont = Typeface.createFromAsset(getAssets(), "iconfont/iconfont.ttf");
        exitv = (TextView)findViewById(R.id.exitbtn_mine);
        exitv.setTypeface(iconfont);
        usertv = (TextView)findViewById(R.id.username_mine);
        usertv.setTypeface(iconfont);
        loginpwtv = (TextView)findViewById(R.id.loginpw_mine);
        loginpwtv.setTypeface(iconfont);
        zhifupwtv = (TextView)findViewById(R.id.zhifupw_mine);
        zhifupwtv.setTypeface(iconfont);
        zhifustyletv = (TextView)findViewById(R.id.zhifustyle_mine);
        loginpwly = (RelativeLayout)findViewById(R.id.loginpwly_mine);
        zhifupwly = (RelativeLayout)findViewById(R.id.zhifuly_mine);
        //返回我的页面
        exitv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               finish();
            }
        });
        //设置登录密码
        loginpwly.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //2种方式，（旧密码方式 ／ 手机验证码方式）
                createDialog();
            }
        });
        //设置支付密码
        zhifupwly.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view){

                Toast.makeText(mine.this,"暂未开通此服务",Toast.LENGTH_SHORT).show();
                //进入支付密码1页面
//                Intent intent = new Intent(mine.this,Zhifupwchange.class);
//                startActivity(intent);
            }
        });
        //退出登录
//        exitlogintv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                //清除token,回到登录页面
//                //弹出alert ,确认是否退出登录。。。
//                AlertDialog.Builder dialog = new AlertDialog.Builder(mine.this);
//                dialog.setTitle("提示");
//                dialog.setMessage("确定退出当前账号?");
//                dialog.setCancelable(true);
//                dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        //进入登录界面
//                        Intent intent = new Intent(mine.this,Login.class);
//                        startActivity(intent);
//                    }
//                });
//                dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        //不做操作
//                    }
//                });
//                dialog.show();
//
//            }
//        });



    }
    public void createDialog(){

        changepwdialog = new Dialog(mine.this, R.style.my_dialog);
        root = (LinearLayout) LayoutInflater.from(mine.this).inflate(
                R.layout.minedialog, null);
        root.findViewById(R.id.btn_open_camera).setOnClickListener(btnlistener);
        root.findViewById(R.id.btn_choose_img).setOnClickListener(btnlistener);
        root.findViewById(R.id.btn_cancel).setOnClickListener(btnlistener);
        changepwdialog.setContentView(root);
        Window dialogWindow = changepwdialog.getWindow();
        dialogWindow.setGravity(Gravity.BOTTOM);
        dialogWindow.setWindowAnimations(R.style.dialogstyle); // 添加动画，先注释掉
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        lp.x = 0; // 新位置X坐标
        lp.y = -20; // 新位置Y坐标
        lp.width = (int) getResources().getDisplayMetrics().widthPixels; // 宽度
      lp.height = WindowManager.LayoutParams.WRAP_CONTENT; // 高度
      lp.alpha = 9f; // 透明度
        root.measure(0, 0);
        lp.height = root.getMeasuredHeight();
        lp.alpha = 9f; // 透明度
        dialogWindow.setAttributes(lp);
        changepwdialog.show();

    }
    private View.OnClickListener btnlistener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_open_camera: // 旧密码方式修改
                    Intent intent = new Intent(mine.this,OldPwchange_login.class);
                    startActivity(intent);
                    break;
                // 新密码方式修改
                case R.id.btn_choose_img:
                    Intent intent2 = new Intent(mine.this,MsgPwchange_login.class);
                    startActivity(intent2);
                    break;
                // 取消
                case R.id.btn_cancel:
                    if (changepwdialog != null) {
                        changepwdialog.dismiss();
                    }
                    break;
            }
        }
    };
}
